//bfs解法
#include <iostream>
#include <queue>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 35;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

queue<PII> q;

int g[N][N];
bool st[N][N];

int n;

void bfs()
{
	for (int i = 0; i < n; i ++ )
	{
		if (g[i][0] == 2) q.push({i, 0});
		if (g[0][i] == 2) q.push({0, i});
		if (g[n - 1][i] == 2) q.push({n - 1, i});
		if (g[i][n - 1] == 2) q.push({i, n - 1});		
	}
	
	
	while (q.size())
	{
		auto a = q.front(); q.pop();

		g[a.x][a.y] = 0;
		st[a.x][a.y] = true;
		
		for (int i = 0; i < 4; i ++ )
		{
			int ax = a.x + dx[i];
			int ay = a.y + dy[i];
			
			if (st[ax][ay] || g[ax][ay] == 1 || ax < 0 || ax >= n || ay < 0 || ay >= n) continue;
			
			q.push({ax, ay});
		}
	}
}

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i ++ )
	{
		for (int j = 0; j < n; j ++ )
		{
			cin >> g[i][j];
			if (!g[i][j]) g[i][j] = 2;
		}
	}

	bfs();
	
	for (int i = 0; i < n; i ++ )
	{
		for (int j = 0; j < n; j ++ )
		{
			cout << g[i][j] << ' ';
		}
		
		puts("");
	}
}

//dfs解法
#include <iostream>

using namespace std;

const int N = 35;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int g[N][N];
bool st[N][N];

int n;

void dfs(int x, int y)
{
	if (st[x][y]) return;
	if (x < 0 || x >= n || y < 0 || y >= n || g[x][y] == 1) return;
	
	g[x][y] = 0;
	st[x][y] = true;
	
	for (int i = 0; i < 4; i ++ )
	{
		dfs(x + dx[i], y + dy[i]);
	}
}

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i ++ )
	{
		for (int j = 0; j < n; j ++ )
		{
			cin >> g[i][j];
			if (!g[i][j]) g[i][j] = 2;
		}
	}
	
	for (int i = 0; i < n; i ++ )
	{
		if (g[i][0] == 2) dfs(i, 0);
		if (g[0][i] == 2) dfs(0, i);
		if (g[n - 1][i] == 2) dfs(n - 1, i);
		if (g[i][n - 1] == 2) dfs(i, n - 1);		
	}
	
	for (int i = 0; i < n; i ++ )
	{
		for (int j = 0; j < n; j ++ )
		{
			cout << g[i][j] << ' ';
		}
		
		puts("");
	}
}